//起始时间
//1980年1月1日星期二
//前面有两个空位
//一年有365天  366天
//需要算出今年是366天还是365天

var year = 2019;
var month = 5;
document.querySelector("#nian").innerHTML = year;
document.querySelector("#yue").innerHTML = month;
//总天数
var days = 0;

//判断这一年是不是闰年
function runNian(y){
    if (y % 400 === 0 || (y % 4 === 0 && y % 100 !==0)){
        return true;
    }else{
        return false;
    }
}

//算1980年到现在的头一年有多少天
for(var i = 1980; i<year; i++){
    if(runNian(i)){
        days += 366;
    }else{
        days += 365;
    }
}




//今年的1月到这个的上一个月有多少天
/*
31
28
31
30
 */

for(var k = 1; k<month; k++){
 switch(k){
     case 1:
         days +=31;
         break;
     case 2:
         if(runNian(year)){
             days += 29;
         }else{
             days += 28;
         }
         break;
     case 3:
         days +=31;
         break;
     case 4:
         days +=30;
         break;
     case 5:
         days +=31;
         break;
     case 6:
         days +=30;
         break;
     case 7:
         days +=31;
         break;
     case 8:
         days +=31;
         break;
     case 9:
         days +=30;
         break;
     case 10:
         days +=31;
         break;
     case 11:
         days +=30;
         break;
     case 12:
         days +=31;
         break;

 }
}









//算一下本月一共有多少天
var day = 0;
    switch(month){
        case 1:
            day +=31;
            break;
        case 2:
            if(runNian(year)){
                day += 29;
            }else{
                day += 28;
            }
            break;
        case 3:
            day +=31;
            break;
        case 4:
            day +=30;
            break;
        case 5:
            day +=31;
            break;
        case 6:
            day +=30;
            break;
        case 7:
            day +=31;
            break;
        case 8:
            day +=31;
            break;
        case 9:
            day +=30;
            break;
        case 10:
            days +=31;
            break;
        case 11:
            day +=30;
            break;
        case 12:
            day +=31;
            break;

    }
console.log(day);


//算一下上个月一共有多少天
var prevDay = 0;
    switch(month - 1){
        case 1:
            prevDay +=31;
            break;
        case 2:
            if(runNian(year)){
                prevDay += 29;
            }else{
                prevDay += 28;
            }
            break;
        case 3:
            prevDay +=31;
            break;
        case 4:
            prevDay +=30;
            break;
        case 5:
            prevDay +=31;
            break;
        case 6:
            prevDay +=30;
            break;
        case 7:
            prevDay +=31;
            break;
        case 8:
            prevDay +=31;
            break;
        case 9:
            prevDay +=30;
            break;
        case 10:
            prevDay +=31;
            break;
        case 11:
            prevDay +=30;
            break;
        case 12:
            prevDay +=31;
            break;

    }
console.log(prevDay);



//因为1980年1月1号是从星期二开始的，我想让它从星期日开始算，所以
days +=2;


console.log(days);



//算出本月的1号是星期几(算出起始位置)
var start = days % 7;
console.log(start);



//算一下当前页面的日历一共可以放多少天
var num = 42;

//前面可以空多少个


//本月有多少天



//下一个月有多少天
var nextDays = num -start - day;


//取到今天是几号
var thisday = new Date().getDate();

var day1 = document.querySelector("#day1");

for(var j = prevDay - start + 1; j<=prevDay; j++){
    day1.innerHTML +="<span class='h'>" + j + "</span>";
}


for(var a = 1; a <= day; a++){
    if(a == thisday){
        day1.innerHTML += "<span class='today'>" + a + "</span>";
    }else{
        day1.innerHTML += "<span>" + a + "</span>";
    }
}


for(var s = 1; s <= nextDays; s++){
    day1.innerHTML += "<span class='h'>" + s + "</span>";
}



/*
1、
先算1980 - 2018年一共多少天

2、
再算2019年1月 - 4月一共多少天

3、
再算本月一共有多少天

4、
根据余数算出前面有几个空位

5、
补充上末尾有几个空位，用for循环补上

*/

